I have been using the Global Search Utility, which has been very helpful to search many terms/modules at the same time. However, I need to show which term was found in its own attribute column.
string SearchTerm[] = {"Term1", "Term2", "Term3", "etc."}
For all obj in module
{
//Search all objects to see if it contains a term.
If (obj."Object Text" || obj."Object Heading" contains SearchTerm[i] )
{
//set the attribute to the term it found.
Set obj."Found Term" = SearchTerm[i]
}
}
SystemAdmin - Fri Jul 27 13:20:58 EDT 2012 |
Re: Global Search To Create Attribute
string SearchTerm[] = {"Term1", "Term2", "Term3", "etc."}
Buffer bufResults = create()
For all obj in module
{
//Search all objects to see if it contains a term.
Comma = ", "
bufResults = ""
for (i=0; i<sizeof(SearchTerm); i++)
{ if (obj."Object Text" || obj."Object Heading" contains SearchTerm[i] )
{ bufResults += Comma
bufReSults += SearchTerm[i]
Comma = ", " // Get ready for next found term, if any
}
//set the attribute to the term it found.
}
obj."Found Term" = tempStringOf(bufResults)
}
delete(bufResults)
|
Re: Global Search To Create Attribute llandale - Fri Jul 27 13:52:24 EDT 2012
string SearchTerm[] = {"Term1", "Term2", "Term3", "etc."}
Buffer bufResults = create()
For all obj in module
{
//Search all objects to see if it contains a term.
Comma = ", "
bufResults = ""
for (i=0; i<sizeof(SearchTerm); i++)
{ if (obj."Object Text" || obj."Object Heading" contains SearchTerm[i] )
{ bufResults += Comma
bufReSults += SearchTerm[i]
Comma = ", " // Get ready for next found term, if any
}
//set the attribute to the term it found.
}
obj."Found Term" = tempStringOf(bufResults)
}
delete(bufResults)
Thank you for the quick reply. When I run the script I still get the error "incorrect arguments for function (contains)". I am not sure if "contains" can be used here? Thanks |
Re: Global Search To Create Attribute SystemAdmin - Fri Jul 27 20:58:56 EDT 2012 |
Re: Global Search To Create Attribute llandale - Sat Jul 28 14:51:22 EDT 2012
Louis,
pragma encoding, "UTF-8"
string SearchTerm[] = {"Term1", "Term2", "Term3", "etc."}
Module m = current
Object o = current
string objectHeading, objectText, objectBoth
Buffer bufResults = create()
for o in m do
{
//search both object text and headings
objectText = richText o."Object Text"
objectHeading = richText o."Object Heading"
objectBoth = objectHeading " " objectText
int offset = null
int length = null
bool matchCase = false
bool reverse = false
Comma = ", "
bufResults = ""
//loop through all terms
for (i=0; i<sizeof(SearchTerm); i++)
{
//Search the text.
if (findPlainText (objectBoth, SearchTerm[i], offset, length, matchCase, reverse))
{
bufResults += SearchTerm[i]
bufResults += Comma
bufResults += "\n"
o."Found Term" = tempStringOf(bufResults) //set the attribute to the term(s) found.
continue // Search remaining terms
}
else
{
null
}
}
}
delete(bufResults)
|
Re: Global Search To Create Attribute
I am trying to extend my original code with so that other users can enter their specifc terms in a dialogue box rather than through the DXL text file.
pragma encoding, "UTF-8"
DB searchDB = create ("Search Utility", styleStandard)
DBE InfoTextDBE = text(searchDB, "Instructions", "Enter Search terms. Enter attribute name for column.", 200, 50, true)
DBE SearchTextDBE = text(searchDB, "Search terms", "", 200, 50, false)
Module m = current
Object o = current
void searchFunction (DB win)
{
Buffer bufResults = create()
string objectHeading, objectText, objectBoth
string searchTerms[] = get SearchTextDBE
/**
//for the entire string entered in the text box
for (i=0; i<sizeof(searchTerms); i++)
{
parse out each term separated by a comma
save each term into an array
bufResults += Terms[i]
then continue until the end of string
}
**/
for o in m do
{
//search both object text and headings
objectText = richText o."Object Text"
objectHeading = richText o."Object Heading"
objectBoth = objectHeading " " objectText
int offset = null
int length = null
bool matchCase = false
bool reverse = false
string Comma
Comma = ", "
bufResults = ""
//loop through all terms in the array
for (i=0; i<sizeof(searchTerms); i++)
{
//Search all objects.
if (findPlainText (objectBoth, searchTerms[i], offset, length, matchCase, reverse))
{
bufResults += searchTerms[i]
bufResults += Comma
bufResults += "\n"
o."SearchTerm" = stringOf(bufResults) //set the attribute to the term(s) found.
continue // Search remaining terms
}
else
{
null
}
}
}
}
void closeWindow (DB searchDB)
{
hide (searchDB)
}
apply (searchDB, "Search Terms", searchFunction)
close (searchDB, true, closeWindow)
show searchDB
|
Re: Global Search To Create Attribute |